<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="权限类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
         <a-select  default-value="1" placeholder="请选择权限类型" v-decorator="['type', validatorRules.type]">
           <a-select-option    value="1">物资入库</a-select-option>
           <a-select-option value="2">物资领用</a-select-option>


         </a-select>


        </a-form-item>
        <a-form-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-select-all-cang-ku v-decorator="['ckId', validatorRules.ckId]"></j-select-all-cang-ku>
        </a-form-item>
        <a-form-item label="人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-search-select-tag   v-decorator="['userId', validatorRules.userId]"
                                :trigger-change="true" dict="sys_user,username,id"
                                placeholder="请选择人员"/>

        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import ImagPreview from '../../jeecg/ImagPreview'
  import JSelectRuKuDepart from '../../../components/jeecgbiz/JSelectRuKuDepart'
  import JSelectAssets from '../../../components/jeecgbiz/JSelectAssets'
  import JImageUpload from '../../../components/jeecg/JImageUpload'
  import JSelectCangKu from '../../../components/jeecgbiz/JSelectCangKu'
  import JSelectAllCangKu from '../../../components/jeecgbiz/JSelectAllCangKu'
  import JSearchSelectTag from '../../../components/dict/JSearchSelectTag'


  export default {
    name: "ZcglAssetFixedCategorySettingModal",
    components: {
      JSelectAllCangKu,JSearchSelectTag
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          userId: {
            rules: [
              { required: true, message: '请选择人员!' },
            ]
          },
          type: {
            rules: [
              { required: true, message: '请选择权限类型!' },
            ]
          },

          ckId: {
            rules: [
              { required: true, message: '请选择仓库!' },
            ]
          },
        },
        url: {
          add: "/zcgl/zcglAssetFixedCategorySetting/add",
          edit: "/zcgl/zcglAssetFixedCategorySetting/edit",
        }
      }
    },
    created () {
      this.form.getFieldDecorator('type', {
        initialValue: '1'})
    },
    methods: {

      selectOK (data) {
        alert(JSON.stringify(data))

        let params = {}
        params.roleId = this.currentRoleId
        params.userIdList = []
        for (var a = 0; a < data.length; a++) {
          params.userIdList.push(data[a])
        }
        console.log(params)
        // postAction(this.url.addUserRole, params).then((res) => {
        //   if (res.success) {
        //     this.loadData2()
        //     this.$message.success(res.message)
        //   } else {
        //     this.$message.warning(res.message)
        //   }
        // })
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'ckId','userId'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'ckId','userId'))
      },

      
    }
  }
</script>